package com.common.component;

import java.util.List;

import com.common.utils.ASObjectConvert;
import com.framework.model.IData;
import com.framework.model.IDataset;
import com.framework.model.impl.DataMap;
import com.framework.model.impl.DatasetList;

import flex.messaging.io.amf.ASObject;

public class PageData{

	private static final long serialVersionUID = 1L;
	private IDataset dataList;
	private IData data;
	private Pagination pagination;
	
	private String orderField ="INTORDER";
	private String orderDirection="DESC";
	
	@SuppressWarnings("unchecked")
	public PageData(ASObject object) throws Exception {
		 dataList = new DatasetList();
		 data =  ASObjectConvert.convertASObject2JavaObject(object,DataMap.class);
		 data.put("orderField", orderField);
		 data.put("orderDirection", orderDirection);
		 if(data.get("page")!=null){
			    pagination= (Pagination)data.get("page");
			}else{
				pagination = new Pagination();
			}
	}

	public IDataset getDataList() {
		return dataList;
	}

	public void setDataList(IDataset dataList) {
		this.dataList = dataList;
	}
	
	@SuppressWarnings("unchecked")
	public void addDataList(List inList) {
		if(inList!=null){
			for (int i = 0; i < inList.size(); i++) {
				this.dataList.add(inList.get(i));
			}
		}
	}
	
	@SuppressWarnings("unchecked")
	public IData getParData() {
		data.put("pagination", getPagination());
		return data;
	}


	@SuppressWarnings("unchecked")
	public IData getData() {
		data.put("dataList", dataList);
		data.put("pagination", getPagination());
		return data;
	}

	public void setData(IData data) {
		this.data = data;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

	public String getOrderField() {
		return orderField;
	}

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}
	
}
